package com.basic.backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.basic.backend.model.entity.ArticleImages;
import com.basic.backend.utils.CommaSplitTypeHandler;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

/**
* @author ASUS
* @description 针对表【article_images】的数据库操作Mapper
* @createDate 2025-03-21 14:38:19
* @Entity com.basic.backend.model.entity.ArticleImages
*/
public interface ArticleImagesMapper extends BaseMapper<ArticleImages> {
    @Select("<script>" +
            "SELECT articleId, images FROM article_images " +
            "WHERE articleId IN " +
            "<foreach item='id' collection='articleIds' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    @Results({
            @Result(property = "articleId", column = "articleId"),
            @Result(property = "images", column = "images",
                    typeHandler = CommaSplitTypeHandler.class) // 使用自定义处理器
    })
    List<ArticleImages> batchSelectImages(@Param("articleIds") List<Long> articleIds);

    @Select("<script>" +
            "SELECT articleId, images FROM article_images " +
            "WHERE articleId IN " +
            "<foreach item='id' collection='articleIds' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    @Results({
            @Result(column = "articleId", property = "articleId"),
            @Result(column = "images", property = "images",
                    typeHandler = CommaSplitTypeHandler.class)
    })
    Collection<Object> batchSelectByArticleIds(List<Long> articleIds);
}




